<?xml version="1.0" encoding="UTF-8" ?> 
<Module>
  <ModulePrefs title="キューピー３分クッキング" height="240" />
  <Content type="html">
    <![CDATA[
      <div id="content_div">
      </div>
  	  <script type="text/javascript">
  	    var date = new Date();
  	    var year = date.getYear()+1900;
  	    var monthWithZero = (date.getMonth()+1);
  	    monthWithZero = monthWithZero < 10 ? "0"+monthWithZero : monthWithZero;
  	    var validDate = date.getDate();
  	    
        function getHtml() {    
          var params = {};
          params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.DOM;
          var url = "http://www.ntv.co.jp/3min/new.xml";
          gadgets.io.makeRequest(url, response, params);
        };
        function response(obj) {
          if( obj.errors != "" ){
              alert(obj.errors);
              return;
          }
          var html = "本日のレシピはありません";
          var domData = obj.data;
          var result = domData.evaluate("//items/item/date[text()="+validDate+"]", domData, null, 7, null);
          if( result.snapshotLength > 0 ){
              var urlRoot = "http://www.ntv.co.jp/3min/";
              var target = result.snapshotItem(0).parentNode;
              var title = domData.evaluate("./title/text()", target, null, 7, null).snapshotItem(0).nodeValue;
              var link = urlRoot + domData.evaluate("./link/text()", target, null, 7, null).snapshotItem(0).nodeValue;
              var pics = urlRoot + domData.evaluate("./pics/text()", target, null, 7, null).snapshotItem(0).nodeValue;
              html = "<p>" + "<a href="+link+" target='_blank'>" + title + "</a></p>"
              html += "<img src='"+pics+"' width='240' height='160'/>";
          }
          document.getElementById('content_div').innerHTML = html;
        };
        gadgets.util.registerOnLoadHandler(getHtml);
  	  </script>
    ]]>
  </Content>
</Module>